/*
 * @Author: 噜噜雯雯 2199987619@qq.com
 * @Date: 2025-06-09 09:49:40
 * @LastEditors: 噜噜雯雯 2199987619@qq.com
 * @LastEditTime: 2025-08-27 15:39:53
 * @FilePath: \linePatrol\vue-element-plus-admin\src\store\modules\plangroup.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { defineStore } from 'pinia'
import { store } from '../index'
import SCADAApi from '@/api/scada'
import { DetectorDetail, MarkerListType, RealGasType } from '@/api/scada/type'

export const useSCADAStore = defineStore('Scadastore', {
  state: () => {
    return {
      RealGasDetail: [] as unknown as RealGasType[],
      DetectorDetail: {} as unknown as DetectorDetail,
      MarkerList: [] as unknown as MarkerListType[]
    }
  },
  getters: {
    //根据id返回部门 模糊查询
    getRealGasDetail:
      (state) =>
      (NameOrdeviceNo: string, Date: string, Sort: string): any => {
        const RealGasDetail = state.RealGasDetail
        if (NameOrdeviceNo != '')
          return RealGasDetail.filter(
            (item) =>
              item.deviceNo?.includes(NameOrdeviceNo) || item.siteName?.includes(NameOrdeviceNo)
          )
        if (Date == 'today' && Sort == 'Asc') {
          return [...RealGasDetail].sort((a, b) => a.dayReports - b.dayReports)
        } else if (Date == 'today' && Sort == 'desc') {
          return [...RealGasDetail].sort((a, b) => b.dayReports - a.dayReports)
        } else if (Date == 'yestoday' && Sort == 'Asc') {
          return [...RealGasDetail].sort((a, b) => a.ydayReports - b.ydayReports)
        } else if (Date == 'yestoday' && Sort == 'desc') {
          console.log(12424)
          return [...RealGasDetail].sort((a, b) => b.ydayReports - a.ydayReports)
        }
        //   return state.RealGasDetail
      },
    getDetectorDetail(): DetectorDetail {
      return this.DetectorDetail
    },
    getMarkerList(): MarkerListType[] {
      return this.MarkerList
    }
  },
  actions: {
    async setRealGasDetail() {
      this.RealGasDetail = await SCADAApi.GetRealGas()
    },
    setDetectorData(data: DetectorDetail) {
      this.DetectorDetail = data
      // console.log(this.DetectorDetail);
    },
    setMarkerList(data: MarkerListType[]) {
      this.MarkerList = data
      // console.log(this.DetectorDetail);
    },
    persist: true
  }
})

export const useLockStoreWithOut = () => {
  return useSCADAStore(store)
}
